package cn.sinata.wanglin.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.xilada.xldutils.adapter.HFRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;
import com.xilada.xldutils.utils.ActivityUtil;
import java.util.List;

import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.model.Active;
import cn.sinata.wanglin.utils.ExpUtils;
import cn.sinata.wanglin.utils.RelativeDateFormat;
import cn.sinata.wanglin.village.activity.ActivedetailActivity;
import cn.sinata.wanglin.village.activity.AllUserInfoActivity;

/**
 *
 * Created by liaoxiang on 16/6/20.
 */
public class ActiveAdapter extends HFRecyclerAdapter<Active> {
    Context mContext;
    public ActiveAdapter(List<Active> mData, Context mContext)
    {
        super(mData, R.layout.item_active);
        this.mContext=mContext;
    }

    @Override
    public void onBind(int position, final Active data, ViewHolder holder) {
        ((SimpleDraweeView) holder.bind(R.id.iv_headview)).setImageURI(data.getHeadUrl());
        if(!TextUtils.isEmpty(data.getName())){
            holder.setText(R.id.tv_username,data.getName());
        }else{
            holder.setText(R.id.tv_username,Constant.DEFULT_NICKNAME);
        }
        switch (ExpUtils.getExpValue(data.getExp())){

            case 1:
                Resources res1 = mContext.getResources();
                Drawable img_off1 = res1.getDrawable(R.mipmap.ic_exp1);
                img_off1.setBounds(0, 0, img_off1.getMinimumWidth(), img_off1.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off1, null); //设置右图标
                break;
            case 2:
                Resources res2 = mContext.getResources();
                Drawable img_off2 = res2.getDrawable(R.mipmap.ic_exp2);
                img_off2.setBounds(0, 0, img_off2.getMinimumWidth(), img_off2.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off2, null); //设置右图标
                break;
            case 3:
                Resources res3 = mContext.getResources();
                Drawable img_off3 = res3.getDrawable(R.mipmap.ic_exp3);
                img_off3.setBounds(0, 0, img_off3.getMinimumWidth(), img_off3.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off3, null); //设置右图标
                break;
            case 4:
                Resources res4 = mContext.getResources();
                Drawable img_off4 = res4.getDrawable(R.mipmap.ic_exp4);
                img_off4.setBounds(0, 0, img_off4.getMinimumWidth(), img_off4.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off4, null); //设置右图标
                break;
            case 5:
                Resources res5 = mContext.getResources();
                Drawable img_off5 = res5.getDrawable(R.mipmap.ic_exp5);
                img_off5.setBounds(0, 0, img_off5.getMinimumWidth(), img_off5.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off5, null); //设置右图标
                break;
            case 6:
                Resources res6 = mContext.getResources();
                Drawable img_off6 = res6.getDrawable(R.mipmap.ic_exp6);
                img_off6.setBounds(0, 0, img_off6.getMinimumWidth(), img_off6.getMinimumHeight());
                ((TextView)holder.bind(R.id.tv_username)).setCompoundDrawables(null, null, img_off6, null); //设置右图标
                break;
        }
        if(!TextUtils.isEmpty(data.getIndustry())){
            holder.setText(R.id.tv_industry,data.getIndustry());
        }else{
            holder.setText(R.id.tv_industry,"暂无");
        }

        if(!TextUtils.isEmpty(data.getBelongLabel())){
            holder.setText(R.id.tv_lable,data.getBelongLabel());
        }else{
            holder.setText(R.id.tv_lable,"暂无");
        }
        holder.setText(R.id.tv_time, RelativeDateFormat.format(data.getCreateDate()));
        if(!TextUtils.isEmpty(data.getTitle())){
            holder.setText(R.id.tv_content,data.getTitle());
        }else{
            holder.setText(R.id.tv_content,"暂无发布内容");
        }
        if(!TextUtils.isEmpty(data.getPoster())){
            ((SimpleDraweeView) holder.bind(R.id.iv_showphoto)).setImageURI(data.getPoster());
             holder.bind(R.id.iv_showphoto).setVisibility(View.VISIBLE);
             holder.bind(R.id.iv_showphoto).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ActivityUtil.create(mContext).go(ActivedetailActivity.class)
                            .put("id",data.getId())
                            .start();
                }
            });
        }else{
             holder.bind(R.id.iv_showphoto).setVisibility(View.GONE);
        }

        holder.setText(R.id.tv_activetime, RelativeDateFormat.getCurrentTimeMMDDHHMM(data.getStartDate())+"开始");

        if(!TextUtils.isEmpty(data.getExes())){
            if("0".equals(data.getExes())){
                holder.setText(R.id.tv_money, "免费");
            }else {
                holder.setText(R.id.tv_money, "￥"+data.getExes());
            }

        }else{
            holder.setText(R.id.tv_money,"暂无价格");
        }
        holder.bind(R.id.tv_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtil.create(mContext).go(ActivedetailActivity.class)
                        .put("id",data.getId())
                        .start();
            }
        });
        holder.bind(R.id.iv_headview).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    ActivityUtil.create(mContext).go(AllUserInfoActivity.class).put("friendID",data.getUserId())
                            .start();

            }
        });


    }
}
